package com.heima.article.listenter;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.HotArticleService;
import com.heima.common.constants.HotArticleConstants;
import com.heima.model.mess.ArticleVisitStreamMess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author DiXiaoNie
 * @since 2023/1/7 15:58
 */

@Component
public class HotArticleListener {
    @Autowired
    private HotArticleService hotArticleService;

    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC)
    public void getMessage(String message) {
        //转换对象
        ArticleVisitStreamMess mess = JSON.parseObject(message, ArticleVisitStreamMess.class);

        this.hotArticleService.updateScore(mess);
    }
}
